home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / StateManager / AlphaTest.fx next >
Encoding:
Text File  |  2004-09-27  |  4.2 KB  |  121 lines

  1. //--------------------------------------------------------------------------------------
  2. //
  3. // Alpha-Tested Pine Lighting Model
  4. // Copyright (c) Microsoft Corporation. All rights reserved.
  5. //
  6. //--------------------------------------------------------------------------------------
  7.  
  8.  
  9. //--------------------------------------------------------------------------------------
  10. // Effect Edit defaults
  11. //--------------------------------------------------------------------------------------
  12.  
  13. string XFile = "pine04.x";   // model
  14. int    BCLR = 0xff202080;    // background
  15. string BIMG  = "lake.bmp";   // Background image
  16.  
  17.  
  18. //--------------------------------------------------------------------------------------
  19. // Scene Setup
  20. //--------------------------------------------------------------------------------------
  21.  
  22. // light direction (world space)
  23. float3 lightDir = {0.577, -0.577, 0.577};
  24.  
  25. // light intensity
  26. float4 I_a = { 0.5f, 0.5f, 0.5f, 1.0f };    // ambient
  27. float4 I_d = { 0.5f, 0.5f, 0.5f, 1.0f };    // diffuse
  28. float4 I_s = { 1.0f, 1.0f, 1.0f, 1.0f };    // specular
  29.  
  30. // Transformation Matrices
  31. matrix matWorld     : WORLD;
  32. matrix matViewProj  : VIEWPROJECTION;
  33.  
  34.  
  35. //--------------------------------------------------------------------------------------
  36. // Material Properties
  37. //--------------------------------------------------------------------------------------
  38.  
  39. // Set by EffectInstance when mesh is loaded
  40. // (Default values provided for Effect Edit)
  41. float4 Diffuse = float4( 1.f, 1.f, 1.f, 1.f );
  42. float4 Ambient = float4( 1.f, 1.f, 1.f, 1.f );
  43.  
  44. // Texture Parameter, annotation specifies default texture for EffectEdit
  45. texture Texture0 < string name = "pine04.dds"; >;
  46.  
  47. // Sampler, for sampling the pine texture
  48. sampler s0 = sampler_state
  49. {
  50.     texture = <Texture0>;
  51.     minfilter = LINEAR;
  52.     mipfilter = LINEAR;
  53.     magfilter  = LINEAR;
  54. };
  55.  
  56. //--------------------------------------------------------------------------------------
  57. // Vertex Shader
  58. //--------------------------------------------------------------------------------------
  59. void VS( in  float3 pos      : POSITION,
  60.          in  float3 norm     : NORMAL,
  61.          in  float2 texcrds  : TEXCOORD,
  62.          out float4 opos     : POSITION,
  63.          out float4 ocolor   : COLOR0,
  64.          out float2 otexcrds : TEXCOORD )
  65. {
  66.     // Transform the vertex to clip space
  67.     opos = mul( float4(pos, 1.f), mul( matWorld, matViewProj ) );
  68.  
  69.     // Calculate the normal (in world-space)
  70.     // Assumes inverse( transpose( matWorld ) ) == matWorld
  71.     float3 norm_w = normalize( mul( norm, (float3x3)matWorld ) );
  72.     
  73.     // Calculate the diffuse lighting coefficient
  74.     // The Pine Primitives are 2-Sided, and may be illuminated from either direction
  75.     float dot = abs( dot( -lightDir, norm_w ) );
  76.     
  77.     // Simple Diffuse/Ambient Lighting
  78.     ocolor = saturate( dot * Diffuse * I_d + Ambient * I_a );
  79.  
  80.     // Pass the texture coordinates to the pixel shader
  81.     otexcrds = texcrds;
  82. }
  83.  
  84. //--------------------------------------------------------------------------------------
  85. // Pixel Shader
  86. //--------------------------------------------------------------------------------------
  87. void PS( in  float4 color   : COLOR,
  88.          in  float2 texcord : TEXCOORD,
  89.          out float4 ocolor  : COLOR )
  90. {
  91.     // Sample the Texture
  92.     float4 tex_color = tex2D( s0, texcord );
  93.     
  94.     // Modulate the texture color by the vertex lighting
  95.     ocolor = tex_color * color;
  96. }
  97.  
  98.  
  99. //--------------------------------------------------------------------------------------
  100. // Default Technique
  101. // Establishes Vertex and Pixel Shader
  102. // Ensures base states are set to required values
  103. // (Other techniques within the scene perturb these states)
  104. //--------------------------------------------------------------------------------------
  105. technique tec0
  106. {
  107.     pass p0
  108.     {
  109.         VertexShader = compile vs_1_1 VS();
  110.         PixelShader  = compile ps_1_4 PS();
  111.  
  112.         ZEnable          = TRUE;
  113.         ZWriteEnable     = TRUE;
  114.         CullMode         = NONE;
  115.         AlphaBlendEnable = FALSE;
  116.         AlphaTestEnable  = TRUE;
  117.         AlphaRef         = 156;
  118.         AlphaFunc        = GREATER;
  119.     }
  120. }
  121.